<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
 	<%@ include file="/WEB-INF/view/jQgrid.jsp"%>
</head>
<body>
<div class="container-fluid" id="main-container">
    <div id="page-content" class="clearfix">
        <div class="row-fluid">
            <div class="row-fluid">
                <!-- 检索  -->
                <div class="ibox-title" style="border-color: white;">
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="form-group form-inline">
                                <span>姓名:</span>
                                <input id="name" type="text" placeholder="请输入姓名" class="input-sm form-control">
                                <span>岗位名称:</span>
                                <input id="position" type="text" placeholder="请输入岗位名称" class="input-sm form-control">
                                <span>公司名称:</span>
                                <input id="companyName" type="text" placeholder="请输入公司名称" class="input-sm form-control">
                                <span> 推荐人：</span>
								<input type="text" class="input-sm form-control" id="userName" onclick="openTree('user');" placeholder="请选择推荐人"
										readonly="readonly"  name="userName"/> 
								<input type="hidden" name="userId" id="userId" />
							</div>
							<div class="form-group form-inline">
								<span>起止时间：</span>
								<input id="startDate" type="text" placeholder="请输入开始时间" class="input-sm form-control form_datetime" readonly="readonly">—
								<input id="endDate" type="text" placeholder="请输入结束时间" class="input-sm form-control form_datetime" readonly="readonly">
                                <a id="find_btn" type="button" class="btn btn-sm btn-primary"> 搜索</a>
                                <a id="reset_btn" type="button" class="btn btn-sm btn-warning"> 重置</a>
                             </div>
                        </div>
                    </div>
                </div>
                <!-- biaogebigin -->
                <div class="ibox-content" style=" padding-left: 0px; margin-top: 10px;">
                    <div class="jqGrid_wrapper">
                        <table id="table_list"></table>
                        <div id="pager_list"></div>
                    </div>
                </div>
                <!-- tableover -->
            </div>
            <!-- PAGE CONTENT ENDS HERE -->

        </div>
        <!--/row-->
    </div>
    <!--/#page-content-->
</div>
<!--/.fluid-container#main-container-->
<script type="text/javascript">
    $(top.hangge());
    $(".form_datetime").datetimepicker({
  	  minView: "month",//设置只显示到月份
  	  format : "yyyy-mm-dd",//日期格式
  	  autoclose:true,//选中关闭
  	  todayBtn: true,//今日按钮
        language:  'zh-CN',
   });
        $.jgrid.defaults.styleUI = "Bootstrap";
        $("#table_list").jqGrid({
            url: '<%=contextPath%>/talentsRecommend/listData',
            datatype: "json",
            postData: {}, //发送数据
            autowidth: true,
            rownumbers: true,
            shrinkToFit: true,
            mtype: "post",
            sortname: 'createDate',
            sortorder: "desc",
            rowNum: 10,
            rowList: [10, 20, 30],
            colNames: [
			"id",
			"岗位名称",
			"公司名称",
			"候选人",
			"推荐结果",
			"推荐时间",
			"推荐人",
			"推荐状态",
			"是否通过",
	        "操作"],
            colModel: [
			    {name: "id",index: "id",hidden: true}, 
				{name:"dEnterprise.positionName",index:"dEnterprise.positionName",width:80},
				{name:"company.name",index:"company.name",width:120,
					formatter: function (value, options, row) {
						var htm ='<a onclick="opencompany(&quot;'+row.companyId+'&quot;);" class="btm-sm btn-link" title="查看公司详情">'+value+'</a>';
						return htm;
						}
				},
				{name:"resume.trueName",index:"resume.trueName",width:50,
					formatter: function (value, options, row) {
						var htm ='<a onclick="openresume(&quot;'+row.talentsId+'&quot;);" class="btm-sm btn-link" title="查看候选人详情">'+value+'</a>';
						return htm;
					}
				},
				{
					formatter: function (value, options, row) {
						var htm ='<a onclick="openresult(&quot;'+row.id+'&quot;,&quot;'+row.companyId+'&quot;);" class="btm-sm btn-link">查看详请</a>';
						return htm;
						},
						width:90
				},
				{name:"createDate",index:"createDate",width:100,editable:false,formatter:"date",formatoptions: {srcformat:'Y-m-d H:i:s',newformat:'Y-m-d H:i:s'}},
				{name:"createUser.truename",index:"createUser.truename",width:50},
				{name:"dictStatus",index:"dictStatus",width:80,
					formatter: function (value, options, row) {
						var htm="";
							htm ='<a onclick="updateStatus(&quot;' + row.id + '&quot;);">'+value+'</a>';
						return htm;
					}
				},
				{name:"isPast",index:"isPast",width:80,
					formatter: function (value, options, row) {
						var htm="";
						if(value == 0){
							htm = "<span class='label label-default'>未反馈</span>";
						}else if(value == 1){
							htm = "<span class='label label-success'>是</span>";
						}else if(value == 2){
							htm = "<span class='label label-danger'>否</span>";
						}
						return htm;
					}
				},
	        {
                formatter: function (cellvalue, options, row) {
                    return " <s:hasPermission name="talentsRecommend:add"><a class='btn btn-sm btn-info' title='下载' onclick='downreport(&quot;" + row.reportFile + "&quot;)'><i class='icon-cloud-download'></i></a></s:hasPermission> "
                         +" <s:hasPermission name="talentsRecommend:edit"><a class='btn btn-sm btn-warning' title='反馈结果' onclick='addfeedback(&quot;" + row.id + "&quot;,&quot;"+row.companyId+"&quot;)'><i class='icon-ok-sign'></i></a></s:hasPermission> "
                         + " <s:hasPermission name="talentsRecommend:delete"><a class='btn btn-sm btn-danger' title='删除' onclick='del(&quot;" + row.id + "&quot;)'><i class='icon-trash'></i></a></s:hasPermission> ";
                },
                width: 100
            }],
            height: $(window).height() - 170,
            pager: "#pager_list",
            multiselect: true,//多选按钮
            //multiboxonly: true,
            viewrecords: true,
            hidegrid: false
        });
        //表格自适应高宽
        $(window).bind("resize", function () {
            var b = $(".jqGrid_wrapper").width();
            $("#table_list").setGridWidth(b);
            $("#table_list").setGridHeight($(window).height() - 170);
        })
        $("#table_list").navGrid('#pager_list', {edit: false, add: false, del: false, search: false})
        /* 判断是否有添加权限 */
        //检索
        $("#find_btn").click(function () {
            var name = $("#name").val();
            var position = $("#position").val();
            var companyName = $("#companyName").val();
            var userId = $("#userId").val();
            //开始时间
            var startDate = $('#startDate').val();
            if(startDate!=""){
          	  startDate=startDate+" 00:00:00"
            }
            //结束时间
            var endDate = $('#endDate').val();
            if(endDate!=""){
            	endDate=endDate+" 23:59:59";
            }
            $("#table_list").jqGrid('setGridParam', {
                postData: {
                	'name': name,
                	'position': position,
                	'companyName': companyName,
                	'createuserid':userId,
                	'startDate':startDate,
                	'endDate':endDate
                	}, //发送数据
                page: 1
            }).trigger("reloadGrid"); //重新载入
        });
        $("#reset_btn").click(function () {
            $("#name").val('');
            $("#position").val('');
            $("#companyName").val('');
            $("#userId").val('');
        	$("#userName").val('');
        	$('#startDate').val('');
        	$('#endDate').val('');
        });
        

    //删除
    function del(id) {
        swalopen(id, "<%=contextPath%>/talentsRecommend/delete");
    };

    //修改
    function showedit(id) {
        openyem("修改推荐记录", "<%=contextPath%>/talentsRecommend/editView?id=" + id, 750, 700);
    }
    
  //添加
    function showadd(id) {
        openyem("添加推荐记录", "<%=contextPath%>/talentsRecommend/addView", 800, 750);
    }
    function downreport(file) {
    	var doc ="<%=contextPath%>/"+file;
		var triggerDownload = $("<a>").attr("href", doc).attr("download", doc).appendTo("body"); 
   	    triggerDownload[0].click(); 
        triggerDownload.remove();
	}
    function addfeedback(recommandId,companyId) {
    	openyem("反馈推荐结果", "<%=contextPath%>/recommendResult/addView?recommandId=" + recommandId +"&companyId=" + companyId, 500, 400);
	}
	function openresult(recommandId,companyId) {
		openyem("查看推荐结果", "<%=contextPath%>/recommendResult/resultView?recommandId=" + recommandId +"&companyId=" + companyId, 800, 600);
	}
	function opencompany(id) {
		window.open("<%=contextPath%>/company/detailView?id="+id);
	}
	function openresume(id) {
		window.open("<%=contextPath%>/resume/detailView?id="+id);
	}
	 function updateStatus(id) {
		  openyem("修改推荐状态", "<%=contextPath%>/talentsRecommend/statusView?id=" + id, 500, 350);
	 }
	  function openTree(obj,types){
		     var ids = $("#"+obj+"Id").val();
		   	 var diag = new top.Dialog();
			 diag.Drag=true;
			 diag.Title ="请选择";
			 diag.URL = '<%=contextPath %>/'+obj+'/openZtree?ids='+ids+"&types=redio";
			 diag.Width = 250;
			 diag.Height = 400;
			 diag.CancelEvent = function(){ //关闭事件
				 var tempid = diag.innerFrame.contentWindow.document.getElementById('tempids').value;
				 var tempname = diag.innerFrame.contentWindow.document.getElementById('tempnames').value;
				if(tempid.length!==0){
					if(typeof(num)=="undefined"){ 
						$("#"+obj+"Id").val(tempid);
						$("#"+obj+"Name").val(tempname);
					}else{
						$("#"+obj+num+"Id").val(tempid);
						$("#"+obj+num+"Name").val(tempname);
					}
				}
				diag.close();
			 };
			 diag.show();
		}
</script>
</body>
</html>

